package com.hz.house.controller;

import com.hz.house.common.ResultBean;
import com.hz.house.service.ArticleService;
import com.hz.house.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 买房必读的各种文章
 * @author lfw
 *
 */
@RestController
@RequestMapping("/api/v2/article")
@Api("买房必读文章相关")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/getArticles")
    @ApiOperation("获取买房必读文章列表，type：文章类型,1.房产新闻,2.独家报道，3.楼市政策，4.土地市场")
    public ResultBean getArticleList(@RequestParam("type") Integer type,@RequestParam("page") Integer page) {
        return articleService.getArticleList(type,page);
    }

    @GetMapping("/getArticleDetail")
    @ApiOperation("获取文章详情，showType为文章展示形式，1外链，2富文本，type为文章的类别")
    public ResultBean getArticleDetail(@RequestParam Integer id) {
        return articleService.getArticleDetail(id);
    }

    @GetMapping("/getArticleHb")
    @ApiOperation("获取文章海报进行分享")
    public ResultBean getArticleHb(@RequestParam Integer id){
        return articleService.getArticleHb(id, CurrentUser.getCurrentUserId());
    }

    @GetMapping("/getSellManDyns")
    @ApiOperation("获取社区置业顾问动态列表")
    public ResultBean getSellManDyns(Integer page) {
        return articleService.getSellManDyns(page);
    }

    @GetMapping("/getManuscripts")
    @ApiOperation("获取楼盘资讯列表")
    public ResultBean getManuscriptList(Integer page) {
        return articleService.getManuscriptList(page);
    }

    @GetMapping("/getHtmlByUrl")
    @ApiOperation("根据url上传解析html并上传html上传")
    public ResultBean getHtmlByUrl(String url) throws IOException {
        return articleService.getHtmlByUrl(url);
    }

}
